Repository navigation
DSA RISC-V: key generation checks g^q mod p = 1 once - #4530
Merged
Merged
Conversation
vg_dsa_generate_key checked the domain with vg_dsa_check_parameters, whose g^q mod p = 1 is a modular exponentiation, then derived the key with vg_dsa_derive_key, which checked the whole domain again, g^q included. Generate.deriveChecked (vg_dsa_derive_key_checked, an internal function) is vg_dsa_derive_key for a domain that passes the checks: of them it keeps only the sizes, which give q's significant octets, and sets up the working spaces as the checks leave them (Prevalidated.setup, as prevalidated verification does); it checks x and y as Derive.body does. Key generation calls it once its domain check has returned 1. It is proven against the existing deriveKeyDomainCheckedContract (Spec/Dsa/DomainChecked.lean, deriveChecked_verified), and on the registers (dcContract: dContract and checkParametersBytes of the domain) for its call from key generation, whose proof establishes the precondition from the check's result and the unchanged domain bytes (derivec_pre). Its correctness is the derivation's (deriveWith_ok, DeriveFn.lean, now generic over the check of the domain), and its constant time composes derivation's levels with prevalidated verification's setup. vg_dsa_derive_key is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TKUFHGabzaozUPN18mLpEv
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4141 (finding 4 of the audit): the RISC-V port of #4411. This PR changes no
Spec/orTCB/file and no Rust code outside the generated RISC-V crate.What was slow
vg_dsa_generate_keychecks the domain withvg_dsa_check_parameters, whoseg^q mod p = 1is a modular exponentiation (exponent q, modulus p). It then derived the key withvg_dsa_derive_key, which ran the whole domain check again (checkParamsinImpl/Dsa/RISCV64/Derive.lean,g^qincluded) before computingg^x. So key generation did three exponentiations modulo p where two are enough.What changed
Generate.deriveChecked(Impl/Dsa/RISCV64/Generate.lean, emitted as the internal functionvg_dsa_derive_key_checked) isvg_dsa_derive_keyfor a domain that has already passed the checks. Of the domain checks it keeps only the sizes, which give q's significant octets. It then sets up the working spaces the way the checks leave them, withPrevalidated.setup(the same code prevalidated verification already uses). It checks x and y exactly asDerive.bodydoes. Unlike x86-64'sderiveChecked, it also skips the cheap checks of g. On RISC-V the setup code for that already existed and was proven, and the precondition guarantees the domain passes every one of those checks.deriveKeyDomainCheckedContract(deriveChecked_verified,Proof/Dsa/RISCV64/DeriveCheckedVerified.lean). The satisfiability witness isvalidKeyWitness's domain, so no newdecide +kernelis needed. Key generation's call uses the register-level formdcContract(dContract∧checkParametersBytesof the domain bytes).deriveKey_correctis generalized over the domain check (deriveWith_ok,DeriveFn.lean), and both derivations instantiate it.setupParams_okissetup_okfor a domain that passesParamsOk(DeriveChecked.lean).DeriveCheckedCT.lean): derivation's levels up to the sizes' branch, then prevalidated verification's setup cuts, thenbody_relD.GKDerive.lean,GKFn.lean,GKCT.lean,GKCTCall.lean): the call now goes tovg_dsa_derive_key_checked.derivec_preestablishes its precondition from the domain check's result (chkOf s₀ = true, already tracked) and the unchanged domain bytes (Ctx.par).vg_dsa_derive_keyitself, whichPrivateKey::from_private_componentscalls, is unchanged. The generated change:vg_dsa_generate_key'scalltarget, and the new internal function.Numbers
Benchmarks workflow (riscv64;
dsa; groupsdsa_generate_key_q[0-9]+; with OpenSSL; base = main 0691e88): https://github.com/pyca/verified-garbage/actions/runs/42406449689 (table to follow when it completes).I could not measure locally: this session runs on an x86-64 Xeon with no RISC-V emulator.
Checks
GKVerified,DeriveCheckedVerifiedandArtifacts.Dsa.RISCV64, and every RISC-V DSA module they import, after rebasing on main 0691e88.EmitOne.lean --check Dsa.RISCV64passes.ci/run_unit_tests.py.check_lean_public_imports.pyis OK on the edited modules.cargo fmt --checkpasses.cargo clippy --all-targets --target riscv64gc-unknown-linux-gnu -- -D warningsandcargo build --lib --release --target riscv64gc-unknown-linux-gnupass. The RISC-V tests run in CI.Generated by Claude Code